//
// Created by liushuai on 2020/4/2.
//
#include "mySqrt.h"
int mySqrt(int x){
    if(x<=1)
        return x;
    else{
        int lower = 0;
        int upper = x;
        int middle = 0;
        long long int double_value = 0;
        while ((upper-lower)!=1){
            middle = (lower+upper)/2;
            double_value = (long)middle*middle;
            if(double_value==x)
                return middle;
            else if(double_value>x)
                upper = middle;
            else
                lower = middle;
        }
        return lower;
    }
}
